const Sequelize = require('sequelize');
const {
    dbName,
    userName,
    host,
    port,
    passWord
} = require('../config/config.js').database;
const db = new Sequelize(dbName, userName, passWord, {
    host,
    dialect: 'mysql',
    logging: true,
    timezone: '+08:00',
    options: {
        port
    },
    define: {
      timestamps: false,
      createdAt: 'created_at',
      updatedAt: 'updated_at',
      deletedAt: 'deleted_at'
    },
    pool: {
        max: 5,
        min: 0,
        idle: 30000
    }
});

db.authenticate().then(res => {
    console.log('数据库链接成功');
}).catch(err => {
    console.log('数据库链接失败');
});

db.sync();
// db.sync({
//     force: true // 数据库每次都会被清空
// });

module.exports = { db }